<template>
  <!-- 创建订单页面 -->
  <div class="main">
    <el-form
      ref="form"
      :model="userInfo"
      label-width="75px"
      :rules="rules"
      :hide-required-asterisk="true"
    >
      <!-- 门店信息 -->
      <div class="one_info">
        <div class="name">门店信息</div>
        <div class="list_">
          <el-form-item label="门店名称" prop="customerName" class="goodsName">
            <el-input
              style="width: 370px"
              v-model="userInfo.customerName"
              placeholder="请选择门店名称"
              @input="handleCustomerName"
              :disabled="isDisabled"
            ></el-input>
            <span
              class="sure_"
              @click="handleAddLable"
              v-if="userInfo.customerId"
              >清空</span
            >
            <div
              class="moudel1"
              v-if="userInfo.customerName && customerList.length > 0"
            >
              <div
                class="row"
                v-for="(item, index) in customerList"
                :key="index"
                @click="handleChooseCustomer(index)"
              >
                <span>{{ item.customerName }}</span
                ><span class="choosed" v-show="item.isChoosed">已选</span>
              </div>
            </div>
          </el-form-item>
          <el-form-item label="手机号码" class="item_" prop="customerPhone">
            <el-input
              :disabled="isDisabled"
              type="tel"
              maxlength="11"
              style="width: 370px"
              v-model="userInfo.customerPhone"
              placeholder="请输入手机号码"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系人" class="item_" prop="customerContact">
            <el-input
              :disabled="isDisabled"
              style="width: 370px"
              v-model="userInfo.customerContact"
              placeholder="请输入联系人"
            ></el-input>
          </el-form-item>
        </div>
        <el-form-item
          label="门店地址"
          class="item_"
          prop="customerReceivingAddress"
        >
          <el-input
            :disabled="isDisabled"
            style="width: 370px"
            v-model="userInfo.customerReceivingAddress"
            placeholder="请输入门店地址"
          ></el-input>
        </el-form-item>

        <div class="rollContent" v-if="!isDisabled">
          <el-row
            v-for="(item1, index1) in addLableList"
            :key="index1"
            style="display: flex"
          >
            <el-form-item :label="index1 == 0 ? '门店标签' : ' '">
              <div class="left_l">
                <div class="item_one">
                  <span class="text">{{ item1.customerType }}</span>
                  <span
                    class="el-icon-close"
                    @click="handleToDel(index1)"
                  ></span>
                </div>
              </div>
            </el-form-item>

            <el-form-item label="" label-width="20px">
              <div class="twoLabel">
                <div
                  class="item_"
                  v-for="(item2, index2) in item1.tagList"
                  :key="index2"
                >
                  <span class="text">{{ item2.customerType }}</span>
                  <span
                    class="el-icon-close"
                    @click="handleDelTagName(index1, index2)"
                  ></span>
                </div>
              </div>
            </el-form-item>
          </el-row>
          <el-row style="display: flex">
            <el-form-item :label="addLableList.length == 0 ? '门店标签' : ' '">
              <el-select
                v-model="customerTypeText"
                placeholder="请选择一级标签"
                size="small"
                style="width: 370px"
                @change="handleOneLabelChange"
              >
                <el-option
                  :label="item.customerType"
                  :value="index"
                  v-for="(item, index) in typeGetList"
                  :key="item.typeId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="" class="textInput" label-width="20px">
              <el-input
                type="text"
                v-model="keyWordLabel"
                placeholder="请输入二级标签名称"
                @input="handleInputLabel"
                style="width: 880px"
              />
            </el-form-item>
            <div class="moudel3" v-show="keyWordLabel">
              <div
                class="row"
                v-for="(item, index) in labelList"
                :key="index"
                @click="handleChooseLabel(index)"
              >
                <span class="text">{{ item.customerType }}</span
                ><span class="choosed" v-show="item.isChoosed">已选</span>
              </div>
            </div>
          </el-row>
        </div>
        <!-- 门店标签 -->
        <div class="labelList" v-if="customerTagList.length > 0 && isDisabled">
          <div class="left_">标签</div>
          <div class="right_">
            <div
              class="item_"
              v-for="(item, index) in customerTagList"
              :key="index"
            >
              <div class="one">{{ item.customerType }}</div>
              <span class="xian">/</span>
              <div
                class="two"
                v-for="(item1, index1) in item.tagList"
                :key="index1"
              >
                {{ item1.customerType }}
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 收货 -->
      <div class="three_info">
        <div class="name_" style="margin-bottom: 20px">收货信息</div>
        <div class="list">
          <div class="item_">
            <span class="one">收货人</span>
            <input
              type="text"
              v-model="addressInfo.receiverName"
              class="desc"
            />
          </div>
          <div class="item_">
            <span class="one">收货电话</span>
            <input
              type="tel"
              v-model="addressInfo.receiverTelephone"
              class="desc"
              maxlength="11"
            />
          </div>
          <div class="item_">
            <span class="one">收货地址</span>
            <input
              type="text"
              v-model="addressInfo.receivingAddress"
              class="desc"
            />
          </div>
        </div>
      </div>
      <!-- 订单信息 -->
      <div class="two_info">
        <div class="name_">订单信息</div>
        <div class="content">
          <el-table
            v-loading="loading"
            :data="groupAddedList"
            style="width: 100%"
          >
            <el-table-column
              label="序号"
              align="center"
              type="index"
              prop=""
              width="100px"
            />
            <el-table-column
              label="商品名称"
              align="center"
              width="200px"
              :show-overflow-tooltip="true"
            >
              <template slot-scope="scope">
                <input
                  v-if="!scope.row.goodsId"
                  class="table_input"
                  type="text"
                  name=""
                  id=""
                  v-model="keyWord"
                  @input="handleInput"
                  style="
                    padding-left: 5px;
                    width: 130px;
                    outline: none;
                    border: 1px solid #ccc;
                  "
                />
                <div class="moudel" v-show="keyWord && !scope.row.goodsId">
                  <div
                    class="row"
                    v-for="(item, index) in goodsList"
                    :key="index"
                    @click="handleChoose(index)"
                  >
                    <span>{{ item.goodsName }}</span
                    ><span class="choosed" v-show="item.isChoosed">已选</span>
                  </div>
                </div>

                <span v-if="scope.row.goodsName">{{
                  scope.row.goodsName
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="售卖单价（元）"
              align="center"
              :show-overflow-tooltip="true"
              prop="goodsPricing"
            >
              <template slot-scope="scope">
                <input
                  v-if="scope.row.goodsId"
                  class="table_input"
                  type="number"
                  name=""
                  id=""
                  @blur="handleQuery"
                  v-model="scope.row.goodsPricing"
                  style="
                    width: 80px;
                    outline: none;
                    border: 1px soild #ccc;
                    text-align: center;
                  "
                />
              </template>
            </el-table-column>
            <el-table-column
              label="数量"
              align="center"
              :show-overflow-tooltip="true"
              prop=""
            >
              <template slot-scope="scope">
                <input
                  v-if="scope.row.goodsId"
                  @blur="handleQuery"
                  class="table_input"
                  type="number"
                  name=""
                  id=""
                  v-model="scope.row.goodsStock"
                  style="
                    width: 80px;
                    outline: none;
                    border: 1px soild #ccc;
                    text-align: center;
                  "
                />
              </template>
            </el-table-column>
            <el-table-column
              label="单位"
              align="center"
              :show-overflow-tooltip="true"
              prop="unit"
            >
              <!-- <template slot-scope="scope">
                <input
                  v-if="scope.row.goodsId"
                  class="table_input"
                  type="text"
                  name=""
                  id=""
                  v-model="scope.row.unit"
                  style="
                    width: 80px;
                    outline: none;
                    border: 1px soild #ccc;
                    text-align: center;
                  "
                />
              </template> -->
            </el-table-column>
            <el-table-column
              label="发货仓库"
              align="center"
              :show-overflow-tooltip="true"
              prop=""
              height="60"
            >
              <template slot-scope="scope">
                <!-- <el-select
                  v-if="scope.row.goodsId"
                  v-model.number="scope.row.deliverStock"
                  class="bottom_scope bottom_scope1"
                  placeholder="选择"
                >
                  <el-option value="">请选择</el-option>
                  <el-option :value="1" label="公司" key="1"></el-option>
                  <el-option :value="2" label="工厂" key="2"></el-option>
                </el-select> -->
                <select v-model="scope.row.deliverStock" v-if="scope.row.goodsId" class="bottom_scope2">
                  <option :value="1" label="公司" key="1">公司</option>
                  <option :value="2" label="工厂" key="2">工厂</option>
                </select>

              </template>
            </el-table-column>

            <el-table-column
              label="小计"
              align="center"
              :show-overflow-tooltip="true"
              prop=""
            >
              <template slot-scope="scope">
                <span v-if="scope.row.goodsId">{{
                  (scope.row.goodsStock * scope.row.goodsPricing).toFixed(2)
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="备注"
              align="center"
              :show-overflow-tooltip="true"
              prop=""
            >
              <template slot-scope="scope">
                <input
                  v-if="scope.row.goodsId"
                  class="table_input"
                  type="text"
                  name=""
                  id=""
                  v-model="scope.row.remarks"
                  style="
                    width: 100px;
                    outline: none;
                    border: 1px soild #ccc;
                    text-align: center;
                  "
                />
              </template>
            </el-table-column>
            <el-table-column label="" align="center">
              <template slot-scope="scope">
                <span
                  v-if="scope.row.goodsId"
                  @click="handleDel(scope.$index, scope.row)"
                  style="color: #999; font-size: 14px"
                  >删除</span
                >
              </template>
            </el-table-column>
          </el-table>

          <!-- 选择模板 -->
          <div class="muban_">
            <el-form-item label="销售模板">
              <el-select
                placeholder="请选择销售模板"
                style="width: 150px; color: #017eff"
                v-model="indexId"
                @change="handleMuBan()"
              >
                <el-option
                  v-for="(item2, index2) in goodsMould"
                  :key="index2"
                  :label="item2.mouldName"
                  :value="item2.indexId"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="订单类型">
              <el-select
                placeholder="请选择订单类型"
                style="width: 150px; color: #017eff"
                v-model="orderStyle"
              >
                <el-option key="1" label="公司订单" value="1"> </el-option>
                <el-option key="2" label="工厂订单" value="2"> </el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
        <div class="footer_list">
          <div class="footer_item">
            <div class="left_">支付状态</div>
            <el-select
              v-model="paymentType"
              placeholder="请选择"
              class="bottom_scope"
              style="width: 100px"
            >
              <el-option value="">请选择</el-option>
              <el-option :value="1" label="已支付"></el-option>
              <el-option :value="0" label="未支付"></el-option>
            </el-select>
          </div>
          <div class="footer_item">
            <div class="left_">支付方式</div>
            <el-select
              v-model="paymentMethod"
              placeholder="请选择"
              class="bottom_scope"
              style="width: 100px"
            >
              <el-option value="">请选择</el-option>
              <el-option :value="1" label="微信"></el-option>
              <el-option :value="2" label="支付宝"></el-option>
              <el-option :value="3" label="现金"></el-option>
              <el-option :value="4" label="银行卡"></el-option>
              <el-option :value="5" label="其他"></el-option>
            </el-select>
          </div>
          <div class="footer_item">
            <div class="left_">公司运费</div>
            <input
              type="number"
              class="right_ right_2"
              v-model="companyFreight"
              style="margin-right: 5px"
              @blur="handleCompanyFreight"
            />
            元
          </div>
          <div class="footer_item">
            <div class="left_">全单折扣</div>
            <input
              type="number"
              class="right_ right_2"
              v-model="discount"
              style="margin-right: 5px"
              @blur="handleDiscount"
            />
            &nbsp; %
          </div>
          <div class="footer_item">
            <div class="left_">抹零</div>
            <input
              type="number"
              class="right_ right_2"
              v-model="smallChange"
              @blur="handleSmallChange"
            />
          </div>
        </div>

        <div class="num_footer">
          订单总计 <span>{{ totalPrice.toFixed(2) }}</span>
        </div>
      </div>
      <el-form-item class="dialog-footer">
        <el-button @click="cancelSend()" class="btn_item">取 消</el-button>
        <el-button
          type="primary"
          @click="submitForm('form')"
          class="btn_item sure_"
          >下单</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { goodsList, goodsMouldList } from "@/api/goods/index";
import {
  customerTypeList,
  customerList,
  customerTypeTagList,
} from "@/api/sale/customer";
import { fondOrder } from "@/api/sale/index";

export default {
  data() {
    return {
      paymentType: 0,
      orderStatus: 0,
      paymentMethod: "",
      companyFreight: 0,
      discount: 100, //折扣
      smallChange: 0, //抹零
      customerTypeText: "",
      activeIndex: "",
      typeId: "",
      labelList: [],
      typeGetList: [],
      keyWordLabel: "",
      addLableList: [], //添加的标签
      isDisabled: false,
      orderId: "",
      orderStyle: "1", //订单类型
      onPath: false,
      indexId: "",
      customerList: [], //门店列表
      customerType: [], //门店类型
      goodsMould: [], //商品模板
      goodsList: [], //商品列表
      keyWord: "",
      groupAddedList: [{}],
      loading: false,
      totalPrice: 0,
      operator: "", //下单人
      userInfo: {
        customerName: "",
        customerReceivingAddress: "",
        customerPhone: "",
        customerContact: "",
        customerId: 0,
        customerTag: "",
      },
      customerTagList: [],
      addressInfo: {
        receiverName: "",
        receivingAddress: "",
        receiverTelephone: "",
      },
      rules: {
        customerName: [
          { message: "请输入门店名称", trigger: "blur", required: true },
        ],
        customerReceivingAddress: [
          { message: "请输入门店地址", trigger: "blur", required: true },
        ],
        customerPhone: [
          { message: "请输入手机号码", trigger: "blur", required: true },
        ],
        customerContact: [
          { message: "请输入联系人", trigger: "blur", required: true },
        ],
      },
      tableData: [],
    };
  },
  mounted() {
    this.operator = localStorage.getItem("userName");
    customerTypeList({ pageNum: 1, pageSize: 20 }).then((res) => {
      //  console.log(res)
      if (res.code == 200) {
        this.typeGetList = res.rows;
      }
    });
    goodsMouldList({ pageNum: 1, pageSize: 20 }).then((res) => {
      //  console.log(res)
      if (res.code == 200) {
        res.rows.forEach((v, i) => {
          v.indexId = i + 1;
        });
        this.goodsMould = res.rows;
        this.goodsMould.unshift({ mouldName: "请选择", indexId: 9999 });
      }
    });
  },
  methods: {
    handleInputLabel() {
      console.log(this.activeIndex);
      if (this.typeId == "") {
        this.$message({
          message: "请选择一级标签",
          type: "success",
        });
        this.keyWordLabel = "";
        return false;
      }
      //输入事件
      customerTypeTagList({
        pageNum: 1,
        pageSize: 20,
        customerType: this.keyWordLabel,
        parentId: this.typeId,
      }).then((res) => {
        if (res.code == 200) {
          this.labelList = res.rows.map((v) => {
            v.isChoosed = false;
            return v;
          });
          console.log(this.addLableList);
          // if (this.activeIndex !== "") {
          this.addLableList[Number(this.activeIndex)].tagList.forEach(
            (v, i) => {
              console.log(v.customerType);
              this.labelList.forEach((item) => {
                if (item.customerType == v.customerType) {
                  item.isChoosed = true;
                }
              });
            }
          );
          // }
        }
      });
    },
    handleOneLabelChange(e) {
      this.isPass = false;
      //一级标签发生变化
      this.keyWordLabel = "";
      this.typeId = this.typeGetList[e].typeId;
      this.labelList.length = 0;
      this.addLableList.forEach((v, i) => {
        if (v.parentId == this.typeGetList[e].typeId) {
          this.isPass = true;
          this.activeIndex = i; //已存在
        }
      });
      if (!this.isPass) {
        this.addLableList.push({
          customerType: this.typeGetList[e].customerType,
          parentId: this.typeGetList[e].typeId,
          tagList: [],
        });
      }
      this.keyWordLabel = "";
    },
    handleToDel(index) {
      //一级标签删除
      this.addLableList.splice(index, 1);
      this.keyWordLabel = "";
      this.customerTypeText = "";
      this.typeId = "";
    },
    handleDelTagName(index, index1) {
      //删除子标签
      this.addLableList[index].tagList.splice(index1, 1);
      this.keyWordLabel = "";
    },
    handleChooseLabel(index) {
      //选择哪个
      if (this.labelList[index].isChoosed) {
        return false;
      }
      this.labelList[index].isChoosed = true;
      if (this.activeIndex === "") {
        this.addLableList[this.addLableList.length - 1].tagList = [
          ...this.addLableList[this.addLableList.length - 1].tagList,
          {
            customerType: this.labelList[index].customerType,
            typeId: this.labelList[index].typeId,
          },
        ];
        this.addLableList[this.addLableList.length - 1].tagList = [
          ...new Set(this.addLableList[this.addLableList.length - 1].tagList),
        ];
      } else {
        this.addLableList[this.activeIndex].tagList = [
          ...this.addLableList[this.activeIndex].tagList,
          {
            customerType: this.labelList[index].customerType,
            typeId: this.labelList[index].typeId,
          },
        ];
        this.addLableList[this.activeIndex].tagList = [
          ...new Set(this.addLableList[this.activeIndex].tagList),
        ];
      }
      this.keyWordLabel = "";
    },
    handleAddLable() {
      //清空
      this.isDisabled = false;
      this.customerTagList = [];
      this.userInfo = {
        customerName: "",
        customerReceivingAddress: "",
        customerPhone: "",
        customerContact: "",
        customerTag: "",
        customerId: "",
      };
    },
    handleCustomerName() {
      //客户输入事件
      if (this.userInfo.customerName == "") {
        this.userInfo.customerId = 0;
      }
      customerList({
        pageNum: 1,
        pageSize: 20,
        customerName: this.userInfo.customerName,
      }).then((res) => {
        if (res.code == 200) {
          this.customerList = res.rows.map((v) => {
            v.isChoosed = false;
            return v;
          });
        }
      });
    },
    handleChooseCustomer(index) {
      //选择哪个
      if (this.customerList[index].isChoosed) {
        return false;
      }
      this.customerList.forEach((v) => {
        v.isChoosed = false;
      });

      this.customerList[index].isChoosed = true;
      if (this.customerList[index].customerContact) {
        this.userInfo.customerContact =
          this.customerList[index].customerContact;
      }
      // console.log(this.customerList[index]);
      this.userInfo.customerName = this.customerList[index].customerName;
      this.userInfo.customerReceivingAddress =
        this.customerList[index].customerReceivingAddress;
      this.userInfo.customerPhone = this.customerList[index].customerPhone;
      this.userInfo.customerId = this.customerList[index].customerId;
      this.userInfo.customerTag = this.customerList[index].customerTag;
      this.customerTagList = this.customerList[index].customerTagList;
      this.customerList.length = 0;
      this.isDisabled = true;
    },
    handleQuery() {
      this.totalPrice = 0;
      this.groupAddedList
        .slice(0, this.groupAddedList.length - 1)
        .forEach((v) => {
          this.totalPrice += Number(v.goodsPricing) * Number(v.goodsStock);
        });
    },
    submitForm(form) {
      //新建订单
      this.onPath = false;
      let groupAddedList = this.groupAddedList.slice(
        0,
        this.groupAddedList.length - 1
      );
      console.log(this.userInfo);
      console.log(this.addressInfo);
      if (!this.isDisabled) {
        this.userInfo.customerTag = JSON.stringify({
          listTag: this.addLableList,
        });
      }
      groupAddedList.forEach((v) => {
        if (v.goodsPricing == "") {
          this.$message({
            message: "订单信息售卖单价不可为空",
            type: "warning",
          });
          this.onPath = true;
          return false;
        }
        if (v.goodsStock == "") {
          this.$message({
            message: "订单信息售卖数量不可为空",
            type: "warning",
          });
          this.onPath = true;
          return false;
        }
      });
      if (this.onPath) {
        return false;
      }
      this.$refs[form].validate((valid) => {
        if (valid) {
          var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
          if (!reg.test(this.userInfo.customerPhone)) {
            this.$message({
              message: "输入的手机号码不合法，请重新输入",
              type: "warning",
            });
            return false;
          }
          if (
            !this.groupAddedList.slice(0, this.groupAddedList.length - 1).length
          ) {
            this.$message({
              message: "请添加商品",
              type: "warning",
            });
            return false;
          }
          // if (!this.addressInfo.receiverName) {
          //   this.$message({
          //     message: "请输入收货人",
          //     type: "warning",
          //   });
          //   return false;
          // } else if (!this.addressInfo.receivingAddress) {
          //   this.$message({
          //     message: "请输入收货地址",
          //     type: "warning",
          //   });
          //   return false;
          // } else if (!this.addressInfo.receiverTelephone) {
          //   this.$message({
          //     message: "请输入收货人电话",
          //     type: "warning",
          //   });
          //   return false;
          // }
          // if (!reg.test(this.addressInfo.receiverTelephone)) {
          //   this.$message({
          //     message: "输入的收货电话不合法，请重新输入",
          //     type: "warning",
          //   });
          //   return false;
          // }
          this.groupAddedList
            .slice(0, this.groupAddedList.length - 1)
            .forEach((v) => {
              v.goodsStock = Number(v.goodsStock);
              v.goodsPricing = Number(v.goodsPricing);
              v.deliverStock = Number(v.deliverStock);
            });
          fondOrder({
            userInfo: JSON.stringify(this.userInfo),
            goodsData: JSON.stringify(
              this.groupAddedList.slice(0, this.groupAddedList.length - 1)
            ),
            operator: this.operator,
            totalAmount: Number(this.totalPrice),
            orderType: Number(this.orderStyle),
            receivingAddress: this.addressInfo.receivingAddress,
            receiverName: this.addressInfo.receiverName,
            receiverTelephone: this.addressInfo.receiverTelephone,
            companyFreight: Number(this.companyFreight),
            paymentType: this.paymentType,
            paymentMethod: Number(this.paymentMethod),
            discount: Number(this.discount),
            smallChange: Number(this.smallChange),
            totalAmount: Number(this.totalPrice).toFixed(2),
            orderStatus: this.orderStatus,
          }).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: "新建订单成功",
                type: "success",
              });
              setTimeout(() => {
                this.$router.go(-1);
                this.ruleForm = {};
                this.goodsList = [];
                this.groupAddedList = [{}];
                this.userInfo = {
                  customerName: "",
                  customerReceivingAddress: "",
                  customerPhone: "",
                  customerContact: "",
                };
                this.addressInfo = {
                  receiverName: "",
                  receivingAddress: "",
                  receiverTelephone: "",
                };
              }, 200);
            }
          });
        } else {
          return false;
        }
      });
    },
    handleCompanyFreight() {
      this.totalPrice = 0;
      this.groupAddedList
        .slice(0, this.groupAddedList.length - 1)
        .forEach((v) => {
          this.totalPrice += Number(v.goodsPricing) * Number(v.goodsStock);
        });
      this.discount = 100;
      this.smallChange = 0;
      this.companyFreight = Number(this.companyFreight).toFixed(2);
      this.totalPrice += Number(this.companyFreight);
    },
    handleDiscount() {
      //折扣
      this.totalPrice = 0;
      this.groupAddedList
        .slice(0, this.groupAddedList.length - 1)
        .forEach((v) => {
          this.totalPrice += Number(v.goodsPricing) * Number(v.goodsStock);
        });
      this.totalPrice += Number(this.companyFreight);

      if (Number(this.discount) > 100 || Number(this.discount) <= 0) {
        this.$message({
          message: "折扣金额不合法",
          type: "warning",
        });
        this.discount = 100;
        return false;
      }
      this.smallChange = 0;
      this.discount = Number(this.discount).toFixed(2);
      this.totalPrice = this.totalPrice * Number(this.discount) * 0.01;
      console.log(this.totalPrice);
    },
    handleSmallChange() {
      this.totalPrice = 0;
      this.groupAddedList
        .slice(0, this.groupAddedList.length - 1)
        .forEach((v) => {
          this.totalPrice += Number(v.goodsPricing) * Number(v.goodsStock);
        });
      this.totalPrice += Number(this.companyFreight);
      this.totalPrice = this.totalPrice * Number(this.discount) * 0.01;

      if (
        Number(this.smallChange) >= Number(this.totalPrice) ||
        Number(this.smallChange) < 0
      ) {
        this.$message({
          message: "抹零金额不合法",
          type: "warning",
        });
        this.smallChange = 0;
        return false;
      }
      this.smallChange = Number(this.smallChange).toFixed(2);
      this.totalPrice = this.totalPrice - Number(this.smallChange);
      console.log(this.totalPrice);
    },
    cancelSend() {
      //取消
      this.userInfo = {
        customerName: "",
        customerReceivingAddress: "",
        customerPhone: "",
        customerContact: "",
        customerType: "",
      };
      this.addressInfo = {
        receiverName: "",
        receivingAddress: "",
        receiverTelephone: "",
      };
      this.groupAddedList = [{}];
      this.goodsList.forEach((v) => {
        v.isChoosed = false;
      });
      this.$router.go(-1);
    },
    handleMuBan() {
      // console.log(this.goodsMould)
      // console.log(this.goodsMould[this.indexId].goodsList)
      //选择模板
      this.goodsList.forEach((v) => {
        v.isChoosed = false;
      });
      if (this.indexId == 9999) {
        this.indexId = "";
        this.groupAddedList = [{}];
        return false;
      }
      this.goodsMould[this.indexId].goodsList.forEach((v, i) => {
        this.goodsList.forEach((item) => {
          if (item.goodsName == v.goodsName) {
            item.isChoosed = true;
          }
        });
      });
      this.groupAddedList = [
        ...this.goodsMould[this.indexId].goodsList.map((v) => {
          v.deliverStock = 1;
          return v;
        }),
        {},
      ];
      this.companyFreight = 0;
      this.discount = 100; //折扣
      this.smallChange = 0; //抹零
      this.totalPrice = 0;
      this.groupAddedList
        .slice(0, this.groupAddedList.length - 1)
        .forEach((v) => {
          this.totalPrice += Number(v.goodsPricing) * Number(v.goodsStock);
        });
      this.keyWord = "";
    },
    handleDel(index, row) {
      //删除事件
      this.groupAddedList.splice(index, 1);
      this.goodsList.forEach((v, i) => {
        if (v.goodsName == row.goodsName) {
          this.goodsList[i].isChoosed = false;
        }
      });
      (this.companyFreight = 0), (this.discount = 100); //折扣
      this.smallChange = 0; //抹零
      this.totalPrice = 0;
      this.groupAddedList
        .slice(0, this.groupAddedList.length - 1)
        .forEach((v) => {
          this.totalPrice += Number(v.goodsPricing) * Number(v.goodsStock);
        });
    },
    handleInput() {
      //商品输入事件
      goodsList({ pageNum: 1, pageSize: 20, goodsName: this.keyWord }).then(
        (res) => {
          if (res.code == 200) {
            this.goodsList = res.rows.map((v) => {
              v.isChoosed = false;
              return v;
            });
            this.groupAddedList.forEach((v, i) => {
              this.goodsList.forEach((item) => {
                if (item.goodsName == v.goodsName) {
                  item.isChoosed = true;
                }
              });
            });
          }
        }
      );
    },
    handleChoose(index) {
      //选择哪个
      if (this.goodsList[index].isChoosed) {
        return false;
      }
      this.goodsList[index].isChoosed = true;
      this.keyWord = "";
      this.groupAddedList.splice(this.groupAddedList.length - 1, 0, {
        goodsName: this.goodsList[index].goodsName,
        goodsPricing: this.goodsList[index].goodsPricing,
        goodsId: this.goodsList[index].goodsId,
        unit: this.goodsList[index].unit,
        remarks: this.goodsList[index].remarks,
        goodsStock: 1,
        deliverStock: 1,
        index: this.groupAddedList.length,
      });
      (this.companyFreight = 0), (this.discount = 100); //折扣
      this.smallChange = 0; //抹零
      this.totalPrice = 0;
      this.groupAddedList
        .slice(0, this.groupAddedList.length - 1)
        .forEach((v) => {
          this.totalPrice += Number(v.goodsPricing) * Number(v.goodsStock);
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.el-input--medium {
  margin-bottom: 10px !important;
}
::v-deep .el-select__caret {
  line-height: 28px !important;
}
.bottom_scope ::v-deep .el-input__inner {
  outline: line !important;
  height: 28px !important;
  line-height: 28px !important;
}
.bottom_scope1 ::v-deep .el-input__inner {
  width: 80px !important;
}
.bottom_scope2{
  cursor: pointer;
    width: 60px;
    height: 26px;
    outline: none;
    border: 1px solid #dcdfe6;
    border-radius: 5px;
}
::v-deep .el-input__inner {
  outline: none !important;
  height: 36px !important;
}
.main {
  background-color: #f7f7f7;
  min-height: 100vh;
  box-sizing: border-box;
  .rollContent {
    // min-height: 300px;
    max-height: 600px;
    overflow: auto;
    .title {
      margin-top: -4px;
      margin-left: 6px;
      font-size: 15px;
      color: #606266;
      position: relative;
      z-index: 6;
    }
    .left_l {
      border: 1px solid #dcdfe6;
      border-radius: 6px;
      width: 370px;
      height: 42px;
      padding-left: 6px;
      .item_one {
        display: flex;
        justify-content: start;
        align-items: center;
        float: left;
        margin-top: 5px;
        cursor: pointer;
        padding: 0 10px;
        height: 32px;
        background: #f3f3f3;
        border-radius: 4px;
        line-height: 32px;
        text-align: center;
        width: auto;
        .text {
          margin-right: 10px;
        }
      }
    }

    span {
      display: inline-block;
    }
  }
  .twoLabel {
    width: 880px;
    padding: 0 5px;
    min-height: 40px;
    // padding-bottom: 20px;
    border: 1px solid #dcdfe6;
    border-radius: 6px;
    display: flex;
    flex-wrap: wrap;
    position: relative;
    .addLable {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #4079ff;
      display: flex;
      align-items: center;
      position: absolute;
      bottom: -5px;
      right: 10px;
      cursor: pointer;
      span {
        margin-left: 3px;
      }
    }
    .item_ {
      cursor: pointer;
      padding: 0 5px;
      height: 32px;
      background: #f3f3f3;
      border-radius: 4px;
      line-height: 32px;
      text-align: center;
      margin-right: 5px;
      margin-top: 3px;
      margin-bottom: 3px;
      // margin-bottom: 5px;
      .text {
        margin-right: 5px;
      }
    }
  }
  .textInput {
    position: relative;
  }
  .moudel3 {
    // z-index: 66;
    // position:absolute;
    // top: 40px;
    // left: 465px;
    position: relative;
    left: -880px;
    top: 40px;
    width: 380px;
    height: 200px;
    overflow: auto;
    background: #f7f7f7;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 13px;
    // margin-left: 80px;
    // margin-top: -20px;
    .row {
      cursor: pointer;
      margin-top: 13px;
      width: 187px;
      height: 25px;
      background: #ffffff;
      border-radius: 8px;
      display: flex;
      padding: 0 8px;
      box-sizing: border-box;
      justify-content: space-between;
      align-items: center;
      .choosed {
        width: 33px;
        height: 18px;
        background: rgba(133, 220, 204, 0.3);
        border-radius: 4px;
        text-align: center;
        line-height: 18px;
        font-size: 12px;
        font-family: Adobe Heiti Std;
        font-weight: normal;
        color: #07b087;
      }
    }
  }
  .moudel {
    // width: 300px;
    height: 150px;
    overflow: auto;
    background: #f7f7f7;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 13px;
    .row {
      cursor: pointer;
      margin-top: 13px;
      width: 116px;
      height: 25px;
      background: #ffffff;
      border-radius: 8px;
      display: flex;
      padding: 0 8px;
      box-sizing: border-box;
      justify-content: space-between;
      align-items: center;
      .choosed {
        width: 33px;
        height: 18px;
        background: rgba(133, 220, 204, 0.3);
        border-radius: 4px;
        text-align: center;
        line-height: 18px;
        font-size: 12px;
        font-family: Adobe Heiti Std;
        font-weight: normal;
        color: #07b087;
      }
    }
  }
  .labelList {
    margin-left: 30px;
    margin-top: 20px;
    display: flex;
    cursor: pointer;
    .left_ {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 700;
      color: #333333;
      margin-right: 30px;
    }
    .right_ {
      .item_ {
        margin-bottom: 10px;
        display: flex;
        .one {
          height: 32px;
          background: #f3f3f3;
          border-radius: 4px;
          text-align: center;
          line-height: 32px;
          padding: 0 10px;
          font-size: 10px;
          // margin-right: 20px;
        }
        .xian {
          // padding-right: 1px;
          padding: 0 25px;
          font-size: 20px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #333333;
          margin-top: -2px;
        }
        .two {
          font-size: 10px;
          margin-right: 10px;
          height: 32px;
          background: #f3f3f3;
          border-radius: 4px;
          line-height: 32px;
          padding: 0 10px;
        }
      }
    }
  }

  .goodsName {
    position: relative;
    .sure_ {
      position: absolute;
      right: 0;
      background: #1890ff;
      height: calc(100% - 10px);
      padding: 0 5px;
      color: #fff;
      font-size: 10px;
      cursor: pointer;
    }
  }
  .moudel1 {
    width: 370px;
    cursor: pointer;
    top: 40px;
    left: 0px;
    position: absolute;
    height: 200px;
    overflow: auto;
    background: #f7f7f7;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 13px;
    z-index: 66;
    padding: 0 20px;
    .row {
      margin-top: 13px;
      // width: 187px;
      width: 100%;
      height: 25px;
      background: #ffffff;
      border-radius: 8px;
      display: flex;
      padding: 0 8px;
      box-sizing: border-box;
      justify-content: space-between;
      align-items: center;
      .choosed {
        width: 33px;
        height: 18px;
        background: rgba(133, 220, 204, 0.3);
        border-radius: 4px;
        text-align: center;
        line-height: 18px;
        font-size: 12px;
        font-family: Adobe Heiti Std;
        font-weight: normal;
        color: #07b087;
      }
    }
  }
  .el-input__inner {
    height: 10px !important;
  }
  .el-input--medium .el-input__icon {
    line-height: 28px !important;
  }
  .el-input--medium .el-input__inner {
    height: 28px !important;
    line-height: 28px !important;
  }
  cursor: pointer;
  .dialog-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 50px;
    .btn_item {
      cursor: pointer;
      width: 130px;
      height: 48px;
      border: 1px solid #c1c1c1;
      border-radius: 6px;
      text-align: center;
      // line-height: 48px;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #666666;
      background-color: #fff;
    }
    .sure_ {
      margin-left: 50px;
      border: none;
      width: 130px;
      height: 48px;
      // background: #01b18e;
      background: #4079ff;
      border-radius: 6px;
      color: #ffffff;
    }
  }
  .table_input {
    width: 60px;
    height: 28px;
    background: #ffffff;
    border-radius: 6px;
    border: 1px solid #ccc;
    outline: none;
  }
  padding: 25px 39px;
  .three_info {
    margin-top: 20px;
    min-height: 100px;
    background-color: #fff;
    border-radius: 12px;
    box-sizing: border-box;
    padding: 29px 32px;
    .name_ {
      font-size: 18px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #333333;
      margin-bottom: 10px;
    }
    .list {
      display: flex;
      align-items: center;
      .item_ {
        display: flex;
        align-items: center;
        .one {
          font-size: 14px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #000000;
          margin-right: 20px;
        }
        .desc {
          padding-left: 10px;
          box-sizing: border-box;
          cursor: pointer;
          width: 240px;
          height: 34px;
          border: 1px solid #e4e4e4;
          border-radius: 6px;
          outline: none;
          font-size: 14px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #777777;
          margin-right: 40px;
        }
      }
    }
  }
  .two_info {
    width: 100%;
    position: relative;
    min-height: 200px;
    cursor: pointer;
    margin-top: 25px;
    width: 100%;
    background: #fff;
    border-radius: 12px;
    padding: 29px 25px;
    padding-bottom: 60px;
    box-sizing: border-box;
    .footer_list {
      position: absolute;
      right: 12%;
      bottom: 13px;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      .footer_item {
        display: flex;
        align-items: center;
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #000000;
        margin-right: 25px;
        .left_ {
          margin-right: 17px;
        }
        .right_1 {
          color: #4079ff;
          font-weight: 300;
        }
        .right_2 {
          width: 80px;
          height: 28px;
          background: #ffffff;
          border: 1px solid #e4e4e4;
          border-radius: 6px;
          text-align: center;
          line-height: 28px;
          outline: none;
        }
      }
    }
    .num_footer {
      display: flex;
      align-items: center;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      color: #000000;
      position: absolute;
      right: 30px;
      bottom: 5px;
      span {
        // margin-top: -3px;
        font-size: 30px;
        margin-left: 10px;
      }
    }
    .el-input--medium {
      width: 60px !important;
      height: 28px !important;
      background: #ffffff !important;
      border-radius: 6px !important;
      border: 1px solid #ccc !important;
      outline: none !important;
    }
    .el-input__inner {
      height: 20px !important;
    }
    .select {
      height: 12px !important;
      position: relative !important;
      z-index: 666;
    }
    .name_ {
      font-size: 18px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #333333;
      margin-bottom: 20px;
    }
    .muban_ {
      display: flex;
      position: absolute;
      right: 30px;
      top: 16px;
      color: #017eff;
    }
  }
  .one_info {
    box-sizing: border-box;
    width: 100%;
    min-height: 180px;
    background: #fff;
    border-radius: 12px;
    padding: 23px 27px;
    .name {
      font-size: 18px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #333333;
    }
    .list_ {
      display: flex;
      flex-wrap: wrap;
      margin-top: 20px;
      .item_ {
        margin-left: 10px;
        // margin-top: 20px;
        // width: 420px;
        // display: flex;
        // justify-content: space-between;
        // align-items: center;
        // height: 36px;
        // margin-right: 20px;
        // margin-top: 20px;
        // .detail {
        //   padding-left: 15px;
        //   padding-right: 6px;
        //   box-sizing: border-box;
        //   font-size: 10px;
        //   font-family: Microsoft YaHei;
        //   font-weight: 400;
        //   color: #333333;
        //   width: 350px;
        //   height: 36px;
        //   border: 1px solid #e7e7e7;
        //   border-radius: 4px;
        //   display: flex;
        //   align-items: center;
        //   justify-content: space-between;
        //   outline: none;
        //   box-sizing: border-box;
        //   // align-item: center;
        // }
      }
    }
  }
}
</style>> 
